from datetime import datetime
from flask import Blueprint, Response, request
from application.logic.IndexLogic import IndexLogic
from application.util.ResponseUtil import ResponseUtil
from application.middleware.LoginMiddleware import login_required
from application.config.SweetConfig import SweetConfig
from application.util.TimeUtil import timestamp_to_datetime, date_difference

# 主页蓝图
index: Blueprint = Blueprint("index", __name__)


@index.get("/create_users")
def create_users() -> Response:
    """
    创建配置的两个用户
    """
    IndexLogic.create_users()
    return ResponseUtil().success()


@index.post("/verification_code")
@login_required
def send_verification_code(token: str) -> Response:
    """
    发送验证码
    :param token: Token
    """
    IndexLogic.send_verification_code(email=request.args.get("email"))
    return ResponseUtil().success()


@index.get("/sweet_days")
def sweet_days() -> Response:
    """
    获取甜蜜开始日期到现在的过了多少天
    """
    days: int = date_difference(start_date=timestamp_to_datetime(timestamp=SweetConfig.sweet_start_date),
                                end_date=datetime.now())
    return ResponseUtil(data=days).success()
